package com.novunda.platform.common.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.novunda.platform.common.exception.ValidationErrorException;

/**
 * .
 * 功能说明：参数校验工具类
 * @author FJ
 * @see 2016年9月22日
 * @version 1.0
 */
public class ParameterValidateUtil {
	
	private ParameterValidateUtil() {
		
	}
	
	/**
	 * .
	 *功能说明：验证邮箱格式
	 * @param email 邮箱
	 * @throws ValidationErrorException 
	 */
	public static void checkEmail(String email) throws ValidationErrorException {
		Pattern pattern = Pattern.compile("^[a-zA-Z0-9]+([._\\-]*[a-zA-Z0-9])*@([a-zA-Z0-9]+[-a-z-A-Z0-9]*[a-zA-Z0-9]+.)(com|cn|net|org)");
		Matcher matcher = pattern.matcher(email);
		if (!matcher.matches()) {
			throw new ValidationErrorException("邮箱格式不正确");
		}
	}
	
	/**
	 * .
	 *功能说明：验证手机号码
	 * @param phone 手机号码
	 * @throws ValidationErrorException 
	 */
	public static void checkPhoneNum(String phone) throws ValidationErrorException {
		Pattern pattern = Pattern.compile("^1[3|4|5|7|8]\\d{9}$");
		Matcher matcher = pattern.matcher(phone);
		if (!matcher.matches()) {
			throw new ValidationErrorException("手机号格式不正确");
		}
	}

	public static boolean isNumeric(String str){
		Pattern pattern = Pattern.compile("[0-9]*");
		return pattern.matcher(str).matches();
	}

	public static void main(String[] src){
		boolean numeric = ParameterValidateUtil.isNumeric("0.123");
		System.out.print(numeric);
		float x = 1.12f;
		long y = (long)x;
		System.out.print(y);
	}
}
